package pta;/**
 * @author： li
 * @date： 2022-04-01 19:18
 * @version 1.0
 */
import java.util.*;
public class 出生年 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashSet<Character> hashSet = new HashSet<Character>();
        int year = sc.nextInt();
        int n =sc.nextInt();
        for(int i=year;i<=3012;i++){
         if(year<1000){
             hashSet.add('0');
             String a =String.valueOf(i);
             for(int j=0;j<a.length();j++)
                 hashSet.add(a.charAt(j));
             if(hashSet.size()==n){
                 System.out.print(i-year+" ");
                 for(int k=1;k<=4-a.length();k++)
                     System.out.print('0');
                 System.out.print(i);
                 break;
             }

         }else{
             String a =String.valueOf(i);
             for(int j=0;j<a.length();j++)
                 hashSet.add(a.charAt(j));
                 if(hashSet.size()==n){
                     System.out.println(i-year+" "+i);
                     break;
                 }

            }
         hashSet.clear();
        }
    }
}
